/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package yassp.client;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PipedOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Milridor
 */
public class FileReaderThread extends Thread {
    private String hash;
    private PipedOutputStream stream;
    
    public FileReaderThread(String fileHash, PipedOutputStream stream) {
        this.hash = fileHash;
        this.stream = stream;
    }
    
    @Override
    public void run() {
        if(FileStore.hashExist(hash)) {
            try {
                FileStore.get(hash).serialize(stream);
                stream.close();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(FileReaderThread.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(FileReaderThread.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
}
